package gatperdut.chato.lucene.indexer.commands;

import gatperdut.chato.constants.CSConstantsLucene;
import gatperdut.chato.lucene.indexer.CMIndexer;
import gatperdut.chato.lucene.parser.CMParser;
import gatperdut.chato.lucene.parser.commands.CommandsParser;
import gatperdut.chato.lucene.parseresult.commands.CommandParseResult;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

import javax.xml.stream.XMLStreamException;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;

public class CommandsIndexer extends CMIndexer {

    public CommandsIndexer( IndexWriter writer ) throws IOException {
        super( writer );
    }

    @Override
    public Document getDocument( File f ) throws IOException {
        Document doc = new Document();
        CommandParseResult cpr = getParser().getParseResult();

        fillDocumentCommonStuff( doc, cpr );

        doc.add( new Field( CSConstantsLucene.FIELD_USAGE, cpr.getUsage(), Field.Store.YES, Field.Index.NOT_ANALYZED ) );

        return doc;
    }

    @Override
    public String getDataPath() {
        return CSConstantsLucene.DATA_PATH;
    }

    @Override
    public CommandsParser getParser() {
        return (CommandsParser) super.getParser();
    }

    @Override
    public CMParser getNewParser( File f ) throws FileNotFoundException, XMLStreamException {
        return new CommandsParser( f );
    }
}
